package org.light.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.light.core.Writeable;
import org.light.utils.WriteableUtil;

public class Enum extends Domain implements Comparable<Domain>,Serializable{
	private static final long serialVersionUID = -2427140823588975832L;
	
	public int compareTo(Domain domain) {
		String myName = this.getStandardName();
		String otherName = domain.getStandardName();
		return myName.compareTo(otherName);
	}

	
	public Domain toPureDomain() throws Exception{
		Domain domain = new Domain();
		domain.setStandardName(this.getStandardName());
		domain.setPlural(this.getPlural());
		domain.setTablePrefix(this.getTablePrefix());
		domain.setLabel(this.getLabel());
		domain.setVerbDeniesStr(this.getVerbDeniesStr());
		
		domain.setSerial(this.getSerial());
		domain.setDbPrefix(this.getPureDbPrefix());
		domain.setPackageToken(this.getPackageToken());
		domain.setLanguage(this.getLanguage());
		domain.setSchema(this.getSchema());
		domain.setDomainSuffix(this.getDomainSuffix());
		domain.setDomainNamingSuffix(this.getDomainNamingSuffix());
		domain.setDaoSuffix(this.getDaoSuffix());
		domain.setDaoimplSuffix(this.getDaoimplSuffix());
		domain.setServiceSuffix(this.getServiceSuffix());
		domain.setServiceimplSuffix(this.getServiceimplSuffix());
		domain.setControllerSuffix(this.getControllerSuffix());
		domain.setControllerNamingSuffix(this.getControllerNamingSuffix());
		domain.setProjectName(this.getStandardName());
		domain.setDbType(this.getDbType());
		domain.setControllerPackage(this.getControllerSuffix());
		domain.setFrontendUi(this.getFrontendUi());
		domain.setBackendUi(this.getBackendUi());
		
		if (this.getDomainId() != null) domain.setDomainId(this.getDomainId());
		if (this.getDomainName() != null) domain.setDomainName(this.getDomainName());
		if (this.getActive() != null) domain.setActive(this.getActive());
		domain.setFields(this.getPlainFields());
		domain.setManyToManies(this.getManyToManies());
		return domain;
	}
	
	public Domain toDomain() throws Exception{
		Domain domain = toPureDomain();
		List<Domain> dummyDomains = new ArrayList<>();
		for (Domain d:this.getDummyDb()) {
			org.light.domain.Enum enum0 = (org.light.domain.Enum) d;
			Domain domain0 = enum0.toPureDomain();
			if (d.getDomainId() != null) domain0.setDomainId(d.getDomainId());
			if (d.getDomainName() != null) domain0.setDomainName(d.getDomainName());
			if (d.getActive() != null) domain0.setActive(d.getActive());
			domain0.setFields(d.getPlainFields());
			domain0.setManyToManies(d.getManyToManies());
			dummyDomains.add(domain0);
		}
		domain.setDummyDb(dummyDomains);		
		return domain;
	}
}
